//
//  ChatMsgModel.m
//  LuQu
//
//  Created by 李亚琪 on 2017/8/17.
//  Copyright © 2017年 mingthink. All rights reserved.
//

#import "ChatMsgModel.h"

@implementation ChatMsgModel

-(NSString *)timeFormat{
    if (!_timeFormat){
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:self.Timestamp.doubleValue/1000];
        NSDateFormatter *formatter = [NSDateFormatter new];
//        [formatter setDateFormat:@"HH:mm"];
//        return _timeFormat = [formatter stringFromDate:confromTimesp];
        
        NSDate *nowDate = [NSDate date];
        NSInteger nowDay = [nowDate mt_day];
        NSInteger dateDay = [date mt_day];
        
        if ([date mt_isThisYear]){
            
            NSInteger nowMonth = [nowDate mt_month];
            NSInteger dateMonth = [date mt_month];
            if (nowMonth != dateMonth){
                [formatter setDateFormat:@"M月d日 HH:mm"];
                return _timeFormat = [formatter stringFromDate:date];
            }
            
            if (nowDay == dateDay){
                [formatter setDateFormat:@"HH:mm"];
                return _timeFormat = [formatter stringFromDate:date];
            }else if (nowDay - dateDay < 2){
                [formatter setDateFormat:@"昨天 HH:mm"];
                return _timeFormat = [formatter stringFromDate:date];
            }else if (nowDay - dateDay < 3){
                [formatter setDateFormat:@"前天 HH:mm"];
                return _timeFormat = [formatter stringFromDate:date];
            }else{
                [formatter setDateFormat:@"M月d日 HH:mm"];
                return _timeFormat = [formatter stringFromDate:date];
            }
            
        }else{
            [formatter setDateFormat:@"yyyy年M月d日 HH:mm"];
            return _timeFormat = [formatter stringFromDate:date];
        }
    }
    return _timeFormat;
}

@end
